﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cspl.AnimalFight.Lib.Interface;
using Cspl.AnimalFight.Lib.EventHandlers;

namespace Cspl.AnimalFight.Lib.Data
{
    public class Horse : AnimalBase,IDefense,IAttackable
    {
        public event DefenseDelegate defenseEvent;


        public bool IsDefending { get; set; }


        public void Defense()
        {
            if (defenseEvent != null)
            {
                defenseEvent(this, new EventHandlers.DefenseEventHandlers
                {
                    AnimalName = this.AnimalName,
                    Target = Animals.Horse
                });

                Console.WriteLine(this._animalName + " is now defend.");
            }
        }

        public override void Escape()
        {
            this.HasEscaped = true;
            Console.WriteLine("Horse has escaped.");
        }


        public void Attacked(int ap)
        {
            if (this.HasEscaped)
            {
                Console.WriteLine("{0} has Escaped, Cannot be Attacked.", this.AnimalName);
            }
            else if (this.IsDead)
            {
                Console.WriteLine("{0} is alreasy dead. Cannot be attcked.", this.AnimalName);
            }
            else
            {
                Console.WriteLine("{0} is being attacked. Current HP ={1}.", this.AnimalName, this.HP);
                int realDP = this.IsDefending ? this.DP + 10 : this.DP;
                this.HP -= (ap - realDP);
                Console.WriteLine("{0} has been attacked. -{1} ", this.AnimalName, ap - realDP);
                Console.WriteLine("Current HP for {0} = {1}", this.AnimalName, this.HP);
                if (this.HP <= 0)
                {
                    Console.WriteLine("the {0} is dead", this.AnimalName);
                    this.IsDead = true;
                }
            }
        }
    }
}
